package com.yuoj.backendcommon.vo;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.yuoj.backendcommon.codesandbox.JudgeInfo;
import com.yuoj.backendcommon.entity.QuestionSubmit;
import com.yuoj.backendcommon.utils.CopyUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * @author 刘渠好
 * @since 2025-01-13 21:24
 * 题目提交视图（脱敏）
 */
@Data
public class QuestionSubmitVO implements Serializable {


    private static final long serialVersionUID = -4420780971585856129L;

    /**
     * id
     */
    private Long id;

    /**
     * 题目 id
     */
    private Long questionId;

    /**
     * 创建用户 id
     */
    private Long userId;

    /**
     * 提交题目用户信息
     */
    private UserVO userVO;


    /**
     * 题目信息
     */
    private QuestionVO questionVO;

    /**
     * 编程语言
     */
    private String language;

    /**
     * 用户代码
     */
    private String code;

    /**
     * 判题状态（0-待判题 1-判题中 2-成功 3-失败）
     */
    private Integer status;

    /**
     * 判题信息（json对象）
     */
    private JudgeInfo judgeInfo;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 删除时间
     */
    private Date updateTime;

    /**
     * 是否删除
     */
     private Integer isDelete;

     public static QuestionSubmitVO obToVo(QuestionSubmit questionSubmit){
         if (questionSubmit == null) {
             return null;
         }
         QuestionSubmitVO questionSubmitVO = CopyUtil.copy (questionSubmit, QuestionSubmitVO.class);
         String info = questionSubmit.getJudgeInfo ();
         if (StrUtil.isNotBlank (info)) {
             questionSubmitVO.setJudgeInfo (JSONUtil.toBean (info, JudgeInfo.class));
         }
         return questionSubmitVO;
     }

     public static  QuestionSubmit voToOj(QuestionSubmitVO questionSubmitVO){
         if (questionSubmitVO == null) {
             return null;
         }
         QuestionSubmit questionSubmit = CopyUtil.copy (questionSubmitVO, QuestionSubmit.class);
         JudgeInfo info = questionSubmitVO.getJudgeInfo ();
         if (info!=null) {
             questionSubmit.setJudgeInfo (JSONUtil.toJsonStr (info));
         }
         return questionSubmit;
     }
}
